package com.kitten.framework.common.utils;

import java.math.RoundingMode;
import java.text.DecimalFormat;

/**
 * @author kitten
 * @description 数字工具类
 */
public class NumberUtils {

    /**
     * 数字工具转换
     * 10000 -> 1万; xxx万 ;100000000+ -> 9999万;
     * @param number
     * @return
     */
    public static String formatNumberString(long number) {
        if (number < 10000) {
            return String.valueOf(number);
        }else if (number < 100000000) {
            double result = number / 10000.0;
            DecimalFormat decimalFormat = new DecimalFormat("#.#"); // 保留1位小数
            decimalFormat.setRoundingMode(RoundingMode.DOWN);   // 舍弃多余的小数
            String format = decimalFormat.format(result);
            return format + "万";
        }else {
            return "9999万";
        }
    }

    public static void main(String[] args) {
        System.out.println(formatNumberString(10000));
        System.out.println(formatNumberString(200000));
        System.out.println(formatNumberString(100000000));
        System.out.println(formatNumberString(100000001));
    }


}
